/*
 * ConjugatedGradient.h
 *
 *      Author: Jerome RD Soine and Christoph A Brand
 *      Institution: Schwarz goup, Institute for Theoretical Physics, Heidelberg University, Germany
 */

#ifndef CONJUGATEDGRADIENT_H_
#define CONJUGATEDGRADIENT_H_

#include "../Optimizer.h"

/*!
 * \brief Implementation of the conjugated gradient (CG) method.
 */

class ConjugatedGradient : public Optimizer
{
public:
	/*!
	 * Creates a conjugated gradient (CG) object.
	 */
	ConjugatedGradient(CellModel * CELL_MODEL, SubstrateModel * SUBSTRATE_MODEL, Comparator * COMPARATOR, string SOLUTION_FOLDER ,unsigned int N_ITERATIONS, unsigned int N_THREADS, double TOLERANCE, double GRADIENT_SPACING_BASE);
	/*!
	 *  Runs an conjugated gradient optimization.
	 */
	virtual void run ();

protected:
	/*!
	 * Applies a conjuagtes gradient iteration step.
	 */
	virtual void iterate();
	/*!
	 * Writes current state of the optimization to solution_folder.
	 */
	virtual void write_current_state(unsigned int step_index);
	/*!
	 * Contains current position in paramters space.
	 */
	vector<double> current_CG_position;
	/*!
	 * Number of current iteration step.
	*/
	unsigned int current_CG_iteration_step;
	/*!
	 * Contains current conjugated gradient.
	*/
	vector<double> conjugated_gradient;
	/*!
	 * Contains last evaluated gradient.
	*/
	vector<double> last_gradient;
	/*!
	 * Contains last conjugated gradient.
	*/
	vector<double> last_conjugated_gradient;
	/*!
	 *  Write Comparator convergence file
	 */
	virtual void write_convergence_file(Worker * w);
	/*!
	 * Writes FA state file containing informations associated with single FAs.
	 */
	virtual void write_FA_state_file(Worker * w);
	/*!
	 * Writes solution vector into file.
	 */
	virtual void write_solution_to_file();
	/*!
	 * Initial fitness value.
	 */
	double initial_fitness;
};


#endif /* CONJUGATEDGRADIENT_H_ */
